clear all
set more off
set type double, perm
capture log close

global d = 0

if $d == 0 { 
global topdir "YOUR DIRECTORY"
global datadir "${topdir}/data"
global outdir "${topdir}/output"
cd "${outdir}"
}

use "${datadir}/nels_final.dta", clear

log using nels_analysis.log, replace




/*  ------------------------------------------------------------------------  */
/*                           Table 4                                          */
/*  ------------------------------------------------------------------------  */

estpost tabstat math [w=wt], by(group) stat(mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99)
esttab using "Table4.csv", replace cells("mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99") nonumber nomtitle 

/*  ------------------------------------------------------------------------  */
/*                           Table A3                                          */
/*  ------------------------------------------------------------------------  */

estpost tabstat math math_g10 [w=wt], by(group) stat(mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99)
esttab using "TableA3.csv", replace cells("mean sd skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99") nonumber nomtitle 


/*  ------------------------------------------------------------------------  */
/*                           Table C1                                         */
/*  ------------------------------------------------------------------------  */

foreach g in WM WW {
	eststo `g'88: regress ln_hrinc math [w=wt] if sample==0 & group2=="`g'", robust
	eststo `g'02: regress ln_hrinc math [w=wt] if sample==1 & group2=="`g'", robust
}
esttab WM88 WM02 WW88 WW02 using "TableC1A.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket 

foreach g in WM WW {
	eststo `g': regress ln_hrinc math math_sample sample [w=wt] if group2=="`g'", robust
}
esttab WM WW using "TableC1B.csv", replace   ///
compress nonumbers mtitle label stats(N r2, labels("Obs" "R-Square")) ///
collabels(none) nonumbers nogaps drop(_cons sample) ///
star(* 0.10 ** 0.05 *** 0.01) se bracket 



/*  ------------------------------------------------------------------------  */
/*                           Figure 3                                         */
/*  ------------------------------------------------------------------------  */

sum math if sample==0 & female==0 [w=wt], d
local mean72 = int(r(mean)*10)/10
local sd72 = int(r(sd)*10)/10
local skew72 = int(r(skewness)*100)/100
local p172 = int(r(p1))
local p572 = int(r(p5))
local p1072 = int(r(p10))
local p2572 = int(r(p25))
local median72 = int(r(p50))
local p7572 = int(r(p75))
local p9072 = int(r(p90))
sum math if sample==1 & female==0 [w=wt], d
local mean88 = int(r(mean)*10)/10
local sd88 = int(r(sd)*10)/10
local skew88 = int(r(skewness)*100)/100
local p188 = int(r(p1))
local p588 = int(r(p5))
local p1088 = int(r(p10))
local p2588 = int(r(p25))
local median88 = int(r(p50))
local p7588 = int(r(p75))
local p9088 = int(r(p90))

twoway (kdensity math if sample==0 & female==0 [w=wt], bw(3) lpattern(_)) ///
		(kdensity math if sample==1 & female==0 [w=wt], bw(3)), ///
		xsc(r(12 88)) xlabel(15(10)85) xtitle("Math score")  ytitle("Density") ///
		scheme(s1color) legend(order(1 "NELS-88" 2 "ELS-02")) ///
		note("  NELS-88:   Mean = `mean72', SD = `sd72', Skewness = `skew72', p1 = `p172', p5 = `p572', p50 = `median72'" "  ELS-02:   Mean = `mean88', SD = `sd88', Skewness = `skew88', p1 = `p188',   p5 = `p588', p50 = `median88'")
graph save Figure3_WM, replace
graph export Figure3_WM.pdf, replace
graph export Figure3_WM.eps, replace


sum math if sample==0 & female==1 [w=wt], d
local mean72 = int(r(mean)*10)/10
local sd72 = int(r(sd)*10)/10
local skew72 = int(r(skewness)*100)/100
local p172 = int(r(p1))
local p572 = int(r(p5))
local p1072 = int(r(p10))
local p2572 = int(r(p25))
local median72 = int(r(p50))
local p7572 = int(r(p75))
local p9072 = int(r(p90))
sum math if sample==1 & female==1 [w=wt], d
local mean88 = int(r(mean)*10)/10
local sd88 = int(r(sd)*10)/10
local skew88 = int(r(skewness)*100)/100
local p188 = int(r(p1))
local p588 = int(r(p5))
local p1088 = int(r(p10))
local p2588 = int(r(p25))
local median88 = int(r(p50))
local p7588 = int(r(p75))
local p9088 = int(r(p90))

twoway (kdensity math if sample==0 & female==1 [w=wt], bw(3) lpattern(_)) ///
		(kdensity math if sample==1 & female==1 [w=wt], bw(3)), ///
		xsc(r(12 88)) xlabel(15(10)85) xtitle("Math score")  ytitle("Density") ///
		scheme(s1color) legend(order(1 "NELS-88" 2 "ELS-02")) ///
		note("  NELS-88:   Mean = `mean72', SD = `sd72', Skewness = `skew72', p1 = `p172', p5 = `p572', p50 = `median72'" "  ELS-02:   Mean = `mean88', SD = `sd88',    Skewness = `skew88', p1 = `p188',   p5 = `p588', p50 = `median88'")
graph save Figure3_WW, replace
graph export Figure3_WW.pdf, replace
graph export Figure3_WW.eps, replace




log close
exit


